// pages/dealOrder/dealOrder.js
const api = require("../../api/api")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    showSendList: [],
    showEvaluation: [],
    show1: [true, true],
    goodsId:''
  },
  onChange(event) {
    this.setData({
      active: event.detail.name,
      showSendList: [],
      showEvaluation: []
    })
    switch (parseInt(this.data.active)) {
      case 0:
        this.goSend()
        break;
      case 1:
        this.viewEvl()
        break;
      default:
        break;
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      showSendList: [],
      showEvaluation: []
    })
    console.log(app.globalData.id)
    console.log(this.data.active)
    switch (parseInt(this.data.active)) {
      case 0:
        this.goSend()
        break;
      case 1:
        this.viewEvl()
        break;
      default:
        break;
    }
  },
  goSend() {
    wx.request({
      url: api.getMySellOrder.url,
      method: api.getMySellOrder.method,
      data: {
        id: app.globalData.id
      },
      success: res => {
        console.log(res)
        var list = res.data.data
        var temp = this.data.showSendList
        for (let index = 0; index < list.length; index++) {
          if (list[index].orderStatus == 0) {
            temp.push(list[index])
          }
        }
        for (let index = 0; index < temp.length; index++) {
          if (temp[index]['img'] != "") {
            temp[index]['img'] = temp[index]['img'].split('|')
          }
        }
        console.log(temp)
        this.setData({
          showSendList: temp
        })

        if (this.data.showSendList.length) {
          var showshow = this.data.show1
          showshow[this.data.active] = false
          this.setData({
            show1: showshow
          })
        } else {
          var showshow = this.data.show1
          showshow[this.data.active] = true
          this.setData({
            show1: showshow
          })
        }
      }
    })
  },
  viewEvl() {
    wx.request({
      url: api.getMySellOrder.url,
      method: api.getMySellOrder.method,
      data: {
        id: app.globalData.id
      },
      success: res => {
        console.log(res)
        
        var list = res.data.data
        var temp2 = this.data.showEvaluation
        for (let index = 0; index < list.length; index++) {
          if (list[index].orderStatus == 2) {
            temp2.push(list[index])
          }
        }

        for (let index = 0; index < temp2.length; index++) {
          if (temp2[index]['img'] != "") {
            temp2[index]['img'] = temp2[index]['img'].split('|')
          }
        }
        this.setData({
          showEvaluation: temp2
        })

        if (this.data.showEvaluation.length) {
          var showshow = this.data.show1
          showshow[this.data.active] = false
          this.setData({
            show1: showshow
          })
        } else {
          var showshow = this.data.show1
          showshow[this.data.active] = true
          this.setData({
            show1: showshow
          })
        }
        console.log(this.data.showEvaluation)
      }
    })
  },
  lisConOrder(e) {
    console.log(e)
    this.setData({
      active: e.detail
    })
    this.viewEvl()
  },
  onShow: function () {
    this.setData({
      showSendList: [],
      showEvaluation: []
    })
    switch (parseInt(this.data.active)) {
      case 0:
        this.goSend()
        break;
      case 1:
        this.viewEvl()
        break;
      default:
        break;
    }
  },

})